/**
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2007，所有权利保留。
 * 
 * 项目名：	rumba
 * 文件名：	MscbOrder.java
 * 模块说明：	
 * 修改历史：
 * Oct 30, 2007 - lxm - 创建。
 */
package com.hd123.rumba.mscb.order;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.hd123.rumba.exception.BusinessException;
import com.hd123.rumba.exception.StringTooLongException;
import com.hd123.rumba.mscb.subscriber.Subscriber;
import com.hd123.rumba.runtime.BaseEntity;

/**
 * 消息订阅单 | 实体 | 实现类
 * 
 * @author lxm
 * 
 */
public class MscbOrder extends BaseEntity implements IMscbOrder {

  private String subjectClass;
  private String event;
  private String constraintContext = "";
  private String constraintDesc = "";
  private String constraintClassName;
  private Subscriber subscriber;
  private String note = "";
  private String flag;
  private Date subscribeTime;
  private List<IMscbOrderPrompt> prompts = new ArrayList<IMscbOrderPrompt>();

  public IMscbOrderPrompt getPromptByProvider(String providerClassName) throws BusinessException {
    if (prompts == null)
      return null;
    for (IMscbOrderPrompt p : prompts) {
      if (providerClassName == null) {
        if (p.getProviderClassName() == null)
          return p;
      } else {
        if (providerClassName.equals(p.getProviderClassName()))
          return p;
      }
    }
    return null;
  }

  public String getConstraintClassName() {
    return constraintClassName;
  }

  public void setConstraintClassName(String constraintClassName) {
    this.constraintClassName = constraintClassName;
  }

  public String getConstraintContext() {
    return constraintContext;
  }

  public void setConstraintContext(String constraintContext) {
    this.constraintContext = constraintContext;
  }

  public String getConstraintDesc() {
    return constraintDesc;
  }

  public void setConstraintDesc(String constraintDesc) {
    this.constraintDesc = constraintDesc;
  }

  public String getEvent() {
    return event;
  }

  public void setEvent(String event) throws StringTooLongException {
    if (event != null)
      event = truncate(event, CMscbOrder.LENGTH_EVENT, "event", CMscbOrder.CAPTION_EVENT);
    this.event = event;
  }

  public String getFlag() {
    return flag;
  }

  public void setFlag(String flag) throws StringTooLongException {
    if (flag != null)
      flag = truncate(flag, CMscbOrder.LENGTH_FLAG, "flag", CMscbOrder.CAPTION_FLAG);
    this.flag = flag;
  }

  public String getNote() {
    return note;
  }

  public void setNote(String note) {
    this.note = note;
  }

  public List<IMscbOrderPrompt> getPrompts() {
    return prompts;
  }

  public void setPrompts(List<IMscbOrderPrompt> prompts) {
    this.prompts = prompts;
  }

  public String getSubjectClass() {
    return subjectClass;
  }

  public void setSubjectClass(String subjectClass) throws StringTooLongException {
    if (subjectClass != null)
      subjectClass = truncate(subjectClass, CMscbOrder.LENGTH_SUBJECTCLASS,
          "subjectClass", CMscbOrder.CAPTION_SUBJECTCLASS);
    this.subjectClass = subjectClass;
  }

  public Subscriber getSubscriber() {
    return subscriber.clone();
  }

  public void setSubscriber(Subscriber subscriber) {
    this.subscriber = subscriber.clone();
  }

  public Date getSubscribeTime() {
    return subscribeTime;
  }

  public void setSubscribeTime(Date subscribeTime) {
    this.subscribeTime = subscribeTime;
  }

}
